﻿using System;
using System.Net;
using SCG.General;

namespace SCG.SolarVengeanceEngine.StarShips
{
    //RemoteViewers
    public class RemoteViewer : StarShip
    {
        //constructor
        public RemoteViewer(SVGame game, Player owner, int viewRange, StarSystem origin)
            : base(game, owner, 3, viewRange, origin)
        {
        }

        //Ship name
        public override string Name
        {
            get
            {
                return "RemoteViewer";
            }
        }

        //description
        public override string Description
        {
            get
            {
                return "RemoteViewers can select a \"View Point\" anywhere on the map that cannot be changed once set. The RemoteViewer can see within the View Point as if Scanners were present there, and can even penetrate Nebula.";
            }
        }

        //ship type
        public override StarShipType ShipType
        {
            get
            {
                return StarShipType.RemoteViewer;
            }
        }

        //Draw scanners on minimap
        public override int Scanners
        {
            get
            {
                if (ViewX >= 0)
                    return Value;
                else
                    return 0;
            }
        }

        //The RemoteViewer's View Point
        public int ViewX
        {
            get
            {
                return _viewX;
            }
            set
            {
                _viewX = value;
            }
        }
        public int ViewY
        {
            get
            {
                return _viewY;
            }
            set
            {
                _viewY = value;
            }
        }

        //They can set view points if not already set
        public override bool CanExecuteOrder(OrderType ot)
        {
            switch (ot)
            {
                case OrderType.SetViewPoint:
                    return ViewX == -1;
                default:
                    return base.CanExecuteOrder(ot);
            }
        }

        //draw the scanner
        public override SCGColor RadiusColor
        {
            get
            {
                if (ViewX >= 0)
                    return ScanShip.ScanRadiusColor;
                else
                    return SCGColor.Transparent;
            }
        }

        //Private members
        private int _viewX = -1;
        private int _viewY = -1;

        //Handle remote viewing visibility processing
        protected internal override void VisibilityProcessing()
        {
            if (ViewX >= 0)
                Game.SetVisibility(new SCGPoint(ViewX, ViewY), Owner, Value, false, true);
        }

        //persistence
        protected override string SubClassPersist()
        {
            Tokenizer tok = new Tokenizer();
            tok.Tokenize(ViewX, ViewY);
            return base.SubClassPersist() + tok.Result;
        }
        protected override void SubClassParse(SVTokenizer tok)
        {
            base.SubClassParse(tok);
            ViewX = tok.TokenInt;
            ViewY = tok.TokenInt;
        }
    }
}
